import { observable, action, autorun, toJS } from 'mobx';
import { WeaTableNew, WeaForm } from 'comsMobx';
import { WeaTools } from 'ecCom';
import { message } from 'antd';
import * as Apis from '../apis/crmContact';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;
export class CrmContactStore {
    title = '';
    @observable contactLogs = [];
    @observable contactLogsTotal = 0;
    @observable contacterInfo = [];
    @observable sellChanceInfo = [];
    @observable customerId = '';
    baseParams = {};
    @observable contactWays = [];
    @observable loading = false;
    @observable verified = false;
    @observable hasRight = false; // 权限

    @observable workplanvisible = false;
    @observable isCreateWorkplan = true;
    @observable workPlanId ='';

    @action
    initDatas = (params = {}) => {
      this.loading = true;
      Apis.getCusContactList(params).then((data) => {
        this.loading = false;
        this.initDatasBack(params, data);
      });
    }

    @action
    initDatasBack(params, data) {
      if (!data.hasright && typeof (data.hasright) !== 'undefined') {
        this.hasRight = data.hasright;
        this.verified = true;
      } else {
        this.hasRight = true;
        this.verified = true;
        this.contactLogs = data.datas.rsList;
        this.contactLogsTotal = data.datas.totalSize;
        this.customerId = params.customerId;
        this.baseParams = params;
        this.contactWays = data.datas.contactWay;
      }
    }

    @action
    getNextCusContactList = (params) => {
      Apis.getCusContactList({ ...this.baseParams, ...params }).then((data) => {
        this.contactLogs = data.datas.rsList;
        this.contactLogsTotal = data.datas.totalSize;
      });
    }

    getContacter = (params = {}) => {
      Apis.getContacterCard(params).then((data) => {
        this.contacterInfo = data.datas.rsList;
      });
    }

    getSellChance = (params = {}) => {
      Apis.getSellchanceCard(params).then((data) => {
        this.sellChanceInfo = data.datas.rsList;
      });
    }

    // 保存数据
    saveContacts = (content, params) => {
      Apis.saveCusContact(content).then((data) => {
        if (data.status == 'success') {
          this.initDatas(params);
          // dispatch(initDatas(params));
          // dispatch(saveContactFields());
          // dispatch(changeTextHeight(1));
        } else {
          Modal.error({
            title: getLabel(15172, '系统提示'),
            content: `操作失败,${data.msgcode}`,
          });
        }
      });
    }

    // 日程显隐控制

    setWorkplanVisible = (bool) => {
      this.workplanvisible = bool;
    }
    // 查看日程
    setWorkplanId =(workplanid) => {
      this.workPlanId = workplanid;
      if (workplanid == '') {
        this.isCreateWorkplan = true;
      } else {
        this.isCreateWorkplan = false;
      }

      this.workplanvisible = true;
    }
}


// WEBPACK FOOTER //
// ./../src4js/pc4mobx/crm/stores/crmContactStore.js
